﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace QLXM.Common
{
    public class CorePage : System.Web.UI.Page
    {
        public string tendangnhap;
        public string maphanquyen;
        public string mathucuoc;
        public int manhomchucdanh;
        public string madonvitothu;
        public int numRowOfPage = int.Parse(System.Configuration.ConfigurationManager.AppSettings["numRowsOfPage"]);
        protected virtual void Page_PreInit(object sender, EventArgs e)
        {
            CheckAuthority();
            WriteActiveIndexMenu();
        }

        private void WriteActiveIndexMenu()
        {
            string modPath = Request.Path;

            int activeMenuIndex = 0;
            if (modPath.StartsWith("/qltc/pages"))
                activeMenuIndex = 1;
            else if (modPath.StartsWith("/qltc/qltn"))
                activeMenuIndex = 2;
            else if (modPath.StartsWith("/qltc/qlttkh"))
                activeMenuIndex = 3;
            else if (modPath.StartsWith("/qltc/cskh"))
                activeMenuIndex = 4;
            else if (modPath.StartsWith("/qltc/diendan"))
                activeMenuIndex = 5;
            else if (modPath.StartsWith("/qltc/manager"))
                activeMenuIndex = 6;

            //Session["ActiveMenuIndex"] = activeMenuIndex;
            ClientScript.RegisterStartupScript(GetType(), "activeMenuIndex", "$(function () {$('.fr-menutop div ul li').eq(" + activeMenuIndex + ").addClass('active');});", true);
        }

        private void CheckAuthority()
        {
            if (Session["tendangnhap"] != null)
            {
                mathucuoc = Session["mathucuoc"].ToString();
                tendangnhap = Session["tendangnhap"].ToString();
                maphanquyen = Session["maphanquyen"].ToString();
                manhomchucdanh = Convert.ToInt32(Session["manhomchucdanh"]);
                madonvitothu = Session["madonvitothu"].ToString();
            }
            else
            {
                Session.Clear();
                Response.Redirect("~/?RedirectUrl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
            }
        }
    }

    public class AdminCorePage : System.Web.UI.Page
    {
        public string tendangnhap;
        public string maphanquyen;
        public string mathucuoc;
        public int manhomchucdanh;
        public int numRowOfPage = int.Parse(System.Configuration.ConfigurationManager.AppSettings["numRowsOfPage"]);
        protected virtual void Page_PreInit(object sender, EventArgs e)
        {
            CheckAuthority();
            WriteActiveIndexMenu();
        }

        private void WriteActiveIndexMenu()
        {
            string modPath = Request.Path;
            int activeMenuIndex = 0;
            if (modPath.StartsWith("/qltc/pages"))
                activeMenuIndex = 1;
            else if (modPath.StartsWith("/qltc/qltn"))
                activeMenuIndex = 2;
            else if (modPath.StartsWith("/qltc/qlttkh"))
                activeMenuIndex = 3;
            else if (modPath.StartsWith("/qltc/cskh"))
                activeMenuIndex = 4;
            else if (modPath.StartsWith("/qltc/diendan"))
                activeMenuIndex = 5;
            else if (modPath.StartsWith("/qltc/manager"))
                activeMenuIndex = 6;

            //Session["ActiveMenuIndex"] = activeMenuIndex;
            ClientScript.RegisterStartupScript(GetType(), "activeMenuIndex", "$(function () {$('.fr-menutop div ul li').eq(" + activeMenuIndex + ").addClass('active');});", true);
        }

        private void CheckAuthority()
        {
            if (Session["tendangnhap"] != null)
            {
                maphanquyen = Session["maphanquyen"].ToString();
                if (maphanquyen == "2")
                {
                    mathucuoc = Session["mathucuoc"].ToString();
                    tendangnhap = Session["tendangnhap"].ToString();
                    manhomchucdanh = Convert.ToInt32(Session["manhomchucdanh"]);
                }
                else
                {
                    Session.Clear();
                    Response.Redirect("~/?RedirectUrl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
                }
            }
            else
            {
                Session.Clear();
                Response.Redirect("~/?RedirectUrl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
            }
        }
    }
}